﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MultipleChoice_ExamGenerator
{
    public partial class View_All_Questions : Form
    {
        public View_All_Questions()
        {
            InitializeComponent();
        }

        private void questionsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.questionsBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.multiplechoicedbDataSet);

        }

        private void View_All_Questions_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'multiplechoicedbDataSet.authors' table. You can move, or remove it, as needed.
            this.authorsTableAdapter.Fill(this.multiplechoicedbDataSet.authors);
            // TODO: This line of code loads data into the 'multiplechoicedbDataSet.questions' table. You can move, or remove it, as needed.
            this.questionsTableAdapter.FillByOwnerIDandPublicQuestions(this.multiplechoicedbDataSet.questions, ActiveAuthor.GetCurrentAuthor());

        }

        private void questionsDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var senderGrid = (DataGridView)sender;

            if (senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex >= 0)
            {
                var showAnswers = new Show_Answers();
                showAnswers.Tag = senderGrid.Rows[e.RowIndex].Cells[6].Value.ToString();

                showAnswers.ShowDialog();
            }
        }

        private void questionsDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
        {


            if (Convert.ToInt32(questionsDataGridView.Rows[e.RowIndex].Cells[0].Value) % 2 == 0)
            {
                e.CellStyle.BackColor = Color.LightCyan;
            }
            else
            {
                e.CellStyle.BackColor = Color.LightBlue;
            }


        }

    }
}